package com.hw.webflux.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;

/**
 * @program: spring-webflux
 * @description:
 * @author: hewei
 * @date: 2021-11-04 17:03
 **/
@Configuration
@EnableWebFlux
public class WebConfig extends WebFluxConfigurationSupport {

    /*跨域配置（通过WebFluxConfiguration实现）*/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("PUT", "DELETE")
//                .allowedHeaders("header1", "header2", "header3")
                .allowedHeaders("*")
                .exposedHeaders("header1", "header2")
                .allowCredentials(true).maxAge(3600);
    }

    /*编解码器配置*/
    @Override
    public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
        configurer.defaultCodecs().enableLoggingRequestDetails(true);
    }

}
